package com.sc.nft.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sc.nft.entity.UserAccountFlow;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

/**
 * <p>
 * 用户三方钱包结算记录 Mapper 接口
 * </p>
 *
 * @author PC
 * @since 2024-10-22
 */
public interface ScUserAccountFlowMapper extends BaseMapper<UserAccountFlow> {

    /**
     * 分账成功减少待结算 增加已结算
     * @param id
     * @param amount
     * @return
     */
    @Update("update sc_user_account_flow set unsettle_amount=unsettle_amount-#{amount} ," +
            " settled_amount=settled_amount+#{amount} where id=#{id}")
    Integer settle(@Param("id") Long id,@Param("amount") BigDecimal amount);


    /**
     * 生成结算单 增加总金额和代结算金额
     * @param id
     * @param amount
     * @return
     */
    @Update("update sc_user_account_flow set total_amount=total_amount + #{amount} ," +
            " unsettle_amount=unsettle_amount+#{amount} where id=#{id}")
    Integer increase(@Param("id") Long id,@Param("amount") BigDecimal amount);

}
